package com.xm.servlet.reception_desk.center;

import lombok.SneakyThrows;

import javax.servlet.http.*;
import javax.servlet.annotation.*;

/**
 * @author lenovo
 */
@WebServlet(name = "PersonalServlet", value = "/personal")
public class PersonalServlet extends HttpServlet {
    @SneakyThrows(Exception.class)
    @Override
    protected void doGet(HttpServletRequest request, HttpServletResponse response)  {
        HttpSession session = request.getSession(false);
        // 获取会话中存储的CSRF令牌
        String sessionToken = null;
        try {
            sessionToken = (String) session.getAttribute("token");
        }catch (Exception e){
            System.out.println("没有登陆");
        }
        // 验证CSRF令牌
        if (sessionToken != null) {
            //菜单
            String menu = request.getParameter("menu") == null ?  "1" : request.getParameter("menu");
            request.setAttribute("menu",menu);
            // 令牌失效
            request.setAttribute("status", true);
        }else{
            //没有登陆
            request.getRequestDispatcher("/WEB-INF/page/reception_desk/login.jsp").forward(request,response);
        }
        request.getRequestDispatcher("/WEB-INF/page/reception_desk/management.jsp").forward(request,response);
    }

}
